#include "LineEditPopupShell.h"
#include <QEvent>
#include "../../Utils/XXlogger.h"

XX_KEY_C(LineEditPopupShell,kLineEdit,"");
XX_KEY_C(LineEditPopupShell,kListWidget,"listWidget");
XX_KEY_C(LineEditPopupShell,kIndicatorButton,"indicatorButton");

LineEditPopupShell::LineEditPopupShell(QObject *parent) : LineEditShell(parent){
}

void LineEditPopupShell::shell(QLineEdit *lineEdit, QAbstractButton *button, QListWidget *listWidget){
    TargetMap map;
    map[kLineEdit] = lineEdit;
    map[kListWidget] = listWidget;
    map[kIndicatorButton] = button;
    LineEditShell::shell(map);
}
void LineEditPopupShell::configPopupListItem(const QStringList &list){
    listWidget()->clear();
    listWidget()->addItems(list);
}

bool LineEditPopupShell::eventFilter(QObject *w, QEvent *e){
    if(w == lineEdit()){
        if(e->type() == QEvent::FocusIn){

        }
        else if(e->type() == QEvent::FocusOut){

        }
        else{

        }
    }
    return eventFilter(w,e);
}
void LineEditPopupShell::installObject(const QString &name, QObject *object){
    if(name == kLineEdit){
        object->installEventFilter(this);
    }
    else if(name == kListWidget){
        QWidget *widget = qobject_cast<QWidget*>(object);
        if(nullptr == widget){

            return;
        }
        _listWidgetLayout
    }
    else if(name == kIndicatorButton){

    }
    else{

    }
}
void LineEditPopupShell::uninstallObject(const QString &name, QObject *object){
    if(name == kLineEdit){
        object->removeEventFilter(this);
    }
    else if(name == kListWidget){

    }
    else if(name == kIndicatorButton){

    }
    else{

    }
}
void LineEditPopupShell::active(bool enable){
    indicatorButton()->setHidden(!enable);
    if(!enable){
        popup(false);
    }
}
void LineEditPopupShell::popup(bool enable){
    listWidget()->setHidden(!enable);
}

QLineEdit* LineEditPopupShell::lineEdit(){
    return ttarget<QLineEdit>(kLineEdit);
}
QListWidget* LineEditPopupShell::listWidget(){
    return ttarget<QListWidget>(kListWidget);
}
QAbstractButton* LineEditPopupShell::indicatorButton(){
    return ttarget<QAbstractButton>(kIndicatorButton);
}

void LineEditPopupShell::indicatorButton_onClicked(bool checked);
void LineEditPopupShell::listWidget_onItemDblClicked(QListWidgetItem *item);
